package argo.hot100.dp;

public class MaxProduct {
    public int maxProduct(int[] nums) {

        if (nums.length == 1) {
            return nums[0];
        }

        int[] dpMax = new int[nums.length];
        int[] dpMin = new int[nums.length];
        dpMax[0] = nums[0];
        dpMin[0] = nums[0];
        int res = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dpMax[i] = Math.max(dpMax[i - 1] * nums[i], Math.max(dpMin[i - 1] * nums[i], nums[i]));
            dpMin[i] = Math.min(dpMax[i - 1] * nums[i], Math.min(dpMin[i - 1] * nums[i], nums[i]));

            res = Math.max(dpMax[i], res);
        }

        return res;
    }


}
